/*
 *  GoodsDetailValueRecycleItemAdapter.java
 *  business
 *
 *  Created by SunDing on 2016/11/2.
 *
 *  Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.yidiandao.business.R;
import com.yidiandao.business.manager.ImageManager;
import com.yidiandao.business.ui.picturescan.PictureScanActivity;
import com.yidiandao.business.utils.ImageLoader;

import java.util.List;

/** 商品详情-商品评价 单条评论展示图片-Adapter */
public class GoodsDetailValueImageAdapter
        extends RecyclerView.Adapter<GoodsDetailValueImageAdapter.ViewHolder> {

    private Activity mActivity;

    private List<List<String>> images;

    public GoodsDetailValueImageAdapter(Activity activity) {
        mActivity = activity;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view =
                LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.item_goods_detail_value_single, parent, false);
        return new ViewHolder(view);
    }

    public void setImages(List<List<String>> images) {
        this.images = images;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {

        final List<String> urls = images.get(position);

        ImageLoader.loadImage(mActivity, holder.ivGoodsImage, urls.get(position));
        holder.ivGoodsImage.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ImageManager.getInstance().setFinalImageList(urls);
                        PictureScanActivity.actionStart(mActivity, position, false);
                    }
                });
    }

    @Override
    public int getItemCount() {
        return images == null ? 0 : images.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView ivGoodsImage;

        public ViewHolder(View itemView) {
            super(itemView);
            ivGoodsImage = (ImageView) itemView.findViewById(R.id.iv_goods_image);
        }
    }
}
